import ConfigParser
import device

parser = None
def __instance():
    global parser
    if parser is None:
        parser = ConfigParser.ConfigParser()
    return parser

def as_dict(section):
    parser = __instance()
    d = {}
    for (name, value) in parser.items(section):
       d[name] = value
    return d
 
def items(section):
    parser = __instance()
    return parser.items(section)

def get(section, option):
    parser = __instance()
    return parser.get(section, str(option))

def get_int(section, option):
    return int(get(section, str(option)))

def get_base16_int(section, option):
    return int(get(section, str(option)), 16)

def get_float(section, option):
    return float(get(section, str(option)))

def get_bool(section, option):
    val = get(section, str(option)).strip().lower()
    if val == 'false':
        return False
    elif val== 'true':
        return True
    else:
        raise ValueError('Got value %s for a boolean.' % (val,))
    
def add_file(file_path):
    parser = __instance()
    parser.read(file_path)

def add_files(file_paths):
    for file_path in file_paths:
        add_file(file_path)